package com.tct.dubbo;

import com.tct.dto.StorageVo;
import com.tct.entity.Storage;
import com.tct.service.StorageService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.AccountADto;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author TcT
 * Date: 2019/6/28.
 * Time: 上午9:13.
 * @Title:
 * @Description:
 */
@Service
public class BDubboServiceImpl implements BDubboService {

    private static final long serialVersionUID = 5135761659213614018L;


    @Autowired
    StorageService storageService;

    @Resource
    ADubboService aDubboService;

    private int flag = 1;


    @Override
    public void save(StorageVo storageVo) {

        //b服务本服务执行持久化
        Storage storage = new Storage();
        BeanUtils.copyProperties(storageVo,storage);
        storage.setCreateTime(new Date());
        storageService.save(storage);

        //回调a服务的保存操作,试试
        AccountADto accountA = new AccountADto();
        accountA.setMoney(200);
        accountA.setUserId("220");

        Long transactionId = 2L;

       // String result = aDubboService.save(accountA,transactionId);
        //System.out.println("第2次回调成功:"+result);

        if (flag == 1){
            System.out.println("b服务保存失败");
            throw new RuntimeException("故意抛异常");
        }

        System.out.println("b服务保存成功");

    }

    @Override
    public List<StorageVo> findAll() {

        List<Storage> all = storageService.findAll();
        return null;
    }
}
